<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
</head>

<body style="font-family:Arial, Helvetica, sans-serif">
<h2>Simple Job Form</h2>
<?php 
if(strlen($this->error)>0){
	echo "<h2 style=\"color:#FF0000\">".$this->error."</h2>";
	}
?>
<form id="form1" name="form1" method="post" action="/repaircenter/quick-form-confirmquote">
  <p><br />
</p>
<table width="800" border="1" cellspacing="0" cellpadding="15">
  <tr>
  	<th align = "left">Brand</th>
  	<td>
  	<select name="mobile_brand" id="mobile_brand">
        <option value="Apple">Apple</option>
        <option value="Samsung">Samsung</option>
        <option value="HTC">HTC</option>
        <option value="Nokia">Nokia</option>
        <option value="Motorola">Motorola</option>
        <option value="Sony">Sony</option>
        <option value="Other">Other</option>
    </select></td>
  </tr>
  <tr>
    <th align = "left">Choose Device :</th>
    <td>
      <label for="type_device"></label>
      <select name="type_device" id="type_device" style=" width:200px;">
      		<?php
	 		 $cateModel = new  Model_DbTable_Pr_Categorymodel();
	 		 $cList = $cateModel->listAll();
			 foreach($cList as $row){
	 		 ?>
      		<option value="<?php echo $row['mobile_model']?>"><?php echo $row['mobile_model']?></option>
      		<?php }?>
      </select> 
      <input type="hidden" name="shop_code" id="shop_code" value="<?php echo $this->shopCode;?>" />
      <br />
      <br />
      (Input your own if not in list)<br/>
      <input type="text" name="mobile_model_other" id="mobile_model_other" />
      </td>
    </tr>
  <tr>
  	<th align = "left">Service Type:</th>
  	<td>
  		<select name="repair_type" id = "repair_type" onchange = "skip()">
  			<option value = "Battery Service">Battery</option>
  			<option value = "Back Cover">Back Cover</option>
  			<option value = "Home Button">Home Button</option>
  			<option value = "Flex">Flex</option>
  		</select><?php echo "No IMEI for Back Cover"?>
  	</td>
  </tr>  
  <tr>
    <th align = "left"><label for="cust_phone">Customer Name: </label></th>
    <td><input type="text" name="cust_name" id="cust_name" style="width:300px;" /></td>
  </tr>
  <tr>
    <th align = "left"><label for="cust_phone">Mobile IMEI : </label></th>
    <td><input type="text" name="mobile_imei" id="mobile_imei" style="width:300px;" />
      <input type="button" name="btn_skip" id="btn_skip" value="Skip IMEI" />
      <br /><div id="imei_result"></div></td>
  </tr>
  <tr>
    <th align = "left">
      <label for="cust_phone">Contact Number: </label></th>
    <td><input type="text" name="cust_phone" id="cust_phone" style="width:300px;" /></td>
  </tr>
  <tr>
  	<th align = "left">Staff Name</th>
  	<td><input type="text" name="staff_name" id="staff_name" style="width:300px;"/></td>
  
  </tr>
</table>
<br />
<input type="submit" name="button" id="button" value="CREATE JOB ID AND PRINT FULL FORM" />
<br />
<br />


</form>
<script language="javascript">
function isIMEI (s) {
var etal = /^[0-9]{15}$/;
  if (!etal.test(s))
    return false;
  if(s.indexOf('11111')>=0)
  	return false;  
  if(s.indexOf('22222')>=0)
  	return false; 
  if(s.indexOf('33333')>=0)
  	return false; 
  if(s.indexOf('44444')>=0)
  	return false;
  if(s.indexOf('55555')>=0)
  	return false; 
  if(s.indexOf('66666')>=0)
  	return false; 
  if(s.indexOf('77777')>=0)
  	return false; 
  if(s.indexOf('88888')>=0)
  	return false; 
  if(s.indexOf('99999')>=0)
  	return false; 
  if(s.indexOf('00000')>=0)
  	return false; 
	
	var str1 = '01234567890';
	var str2 = '09876543210';
	
	for(var i = 0; i < 5; i++){
		var substr = str1.substr(i,5);
		if(s.indexOf(substr)>=0)
		return false;		
	}
	for(var i = 0; i < 5; i++){
		var substr = str2.substr(i,5);
		if(s.indexOf(substr)>=0)
		return false;		
	}
  			
	
  sum = 0; mul = 2; l = 14;
  for (i = 0; i < l; i++) {
    digit = s.substring(l-i-1,l-i);
    tp = parseInt(digit,10)*mul;
    if (tp >= 10)
         sum += (tp % 10) +1;
    else
         sum += tp;
    if (mul == 1)
         mul++;
    else
         mul--;
    }
  chk = ((10 - (sum % 10)) % 10);
  if (chk != parseInt(s.substring(14,15),10))
    return false;
  return true;
}


$("#mobile_imei").change(function(){
	
		var checkImei = $("#mobile_imei").val();
		if(isIMEI(checkImei)){
			$("#imei_result").html("<span style='color:#00DD00;'>IMEI Check Pass</span>");
			//document.getElementById('btn_submitit').removeAttribute("disabled");
			} 
		else{
			if(checkImei == '000000000000000'){
			$("#imei_result").html("<span style = 'color:#FF0000;'>The IMEI Skipped</span>");	
				}
			else{	
			$("#imei_result").html("<span style = 'color:#FF0000;'>The IMEI You Input is Invalidated !!</span>");
			}

			}		
	});	
	
$("#btn_skip").click(function(event){
	event.preventDefault();
	$("#mobile_imei").val('000000000000000');
	});	

function skip(){
		if($("#repair_type").val() == 'Back Cover'){
			$("#mobile_imei").val('000000000000000');
		}
	};
</script>
</body>

</html>
